#include "ffz/ffzconfig.h"
#include "contiki-net.h"
#define DEBUG DEBUG_PRINT
#include "ffz/debug.h"
uint16_t button_counter = 0;

char action_list[ACTION_LENGTH + 1][10] = {"", "show", "elect", "add"};
uint16_t id = 0;

uint16_t button_click()
{
    button_counter++;
    if (button_counter > ACTION_LENGTH)
    {
        button_counter = 0;
    }
    return button_counter;
}
uint16_t button_clear()
{
    uint16_t data = button_counter;
    button_counter = 0;
    return data;
}
char *get_action_name(uint16_t index)
{
    if (index <= ACTION_LENGTH)
    {
        return action_list[index];
    }
    return action_list[0];
}
void print_local_addresses_and_set_id(void)
{
    int i;
    uint8_t state;

    PRINTF("Server IPv6 addresses:\n");
    for (i = 0; i < UIP_DS6_ADDR_NB; i++)
    {
        state = uip_ds6_if.addr_list[i].state;
        if (uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state == ADDR_PREFERRED))
        {
            PRINTF("  ");
            PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
            PRINTF("\n");
            id = (&uip_ds6_if.addr_list[i].ipaddr)->u16[7] / HEX_DOUBLE;
            PRINTF("id = %d\n", id);
            if (state == ADDR_TENTATIVE)
            {
                uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
            }
        }
    }
}
uint16_t raftTableLocalId()
{
    return id;
}